package com.itheima.web;

import com.itheima.service.SetmealService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import com.itheima.vo.SetmealVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
@PreAuthorize("hasAuthority('admin')")
public class SetmealController {

    @DubboReference
    private SetmealService setmealService;

    //保存和编辑
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('save_setmeal')")
    public boolean save(@RequestBody SetmealVO setmealVO){

       return setmealService.saveSetmeal(setmealVO);

    }

    //分页
    @PostMapping("/findByPage")
    @PreAuthorize("hasAuthority('search_setmeal')")
    public PageResult findByPage(@RequestBody QueryPageBean pageBean){
        return setmealService.findByPage(pageBean);
    }

    //逻辑删除
    @GetMapping("/deleteById/{id}")
    @PreAuthorize("hasAuthority('del_setmeal')")
    public boolean deleteById(@PathVariable("id")Long id){
        return setmealService.removeById(id);

    }
}